package com.xlhj.boot.service.impl;

import com.xlhj.boot.service.FanoutProducerService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author: liucaijing
 * @description: FanoutProducerServiceImpl
 * @date: 2021/10/20 9:01
 */
@Service
public class FanoutProducerServiceImpl implements FanoutProducerService {

    private static final String FANOUT_EXCHANGE_NAME = "fanout-exchange";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendMessage(String message) {
        String uuid = UUID.randomUUID().toString();
        CorrelationData correlationData = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(FANOUT_EXCHANGE_NAME, null, message, correlationData);
    }
}
